use askama::Template;
use axum::{extract::Query, response::IntoResponse};
use rbatis::PageRequest;
use tower_cookies::Cookies;

use crate::{config::AppContext, domain::reply::Reply, QueryParam, TemplateResponse};

use super::base::{base, BaseData, Pagination};
use crate::template::filters;

#[derive(Template)]
#[template(path = "reply.html")]
pub struct ReplyTemplate {
    page: Pagination<Reply>,
    base: BaseData,
}
pub async fn index(cookies: Cookies, page: Query<QueryParam>) -> impl IntoResponse {
    let param = page.0;
    let page_request = PageRequest::new_option(param.page_no, param.page_size);
    let page = Reply::select_page(AppContext::rbatis(), &page_request)
        .await
        .unwrap();
    let template = ReplyTemplate {
        page: Pagination::new(page),
        base: base(cookies).await,
    };
    TemplateResponse(template)
}
